package LeetCodeP;

import java.util.HashMap;

public class Solution771 {

    public static int numJewelsInStones(String J, String S) {
        int count=0;

        for (int i=0;i<J.length();i++){
            for (int j=0;j<S.length();j++){
                if (J.charAt(i)==S.charAt(j)){
                    count++;
                }
            }
        }
        System.out.println(count);

        return count;
    }


    public static int numJewelsInStones01(String J, String S) {
        int count =0;
        HashMap<String, Integer> map = new HashMap<>();
        for (int i=0;i<S.length();i++){
            String a=S.substring(i,i+1);
            if (map.get(a)==null){
                System.out.println("if null a is:"+a);
                map.put(a,1);
            }else {
                System.out.println("a:"+a);
                System.out.println("map.get(a):"+map.get(a));
                map.put(a,map.get(a)+1);
            }
        }

        for (int i=0;i<J.length();i++){
            String b=J.substring(i,i+1);
            if (map.containsKey(b)){
                count=count+map.get(b);
                System.out.println("map.get(b):"+map.get(b));
            }
        }

        System.out.println(count);

        return  count;

    }



    public static void main(String[] args) {
        String J="abzZ";
        String S="aZZ";
       /* numJewelsInStones(J,S);*/
        numJewelsInStones01(J,S);
    }


}
